package com.why.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.why.aop.LogAnn;
import com.why.entity.Cop;
import com.why.entity.Copvo;
import com.why.entity.Result;
import com.why.entity.Search;
import com.why.service.ICopvoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.OverridesAttribute;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author hy-woo
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/copvo")
public class CopvoController {

    @Autowired
    ICopvoService copvoService;

    @RequestMapping("/list")
    public Result list(@RequestBody Search search){
        Page<Copvo> copPage = new Page<>(search.getPage(), search.getPageSize());
        QueryWrapper<Copvo> wrapper = new QueryWrapper<>();
        if (search.getCoarea()!=null){
            wrapper.eq("coarea",search.getCoarea());
        }
        if (search.getCoscope()!=null){
            wrapper.eq("coscope",search.getCoscope());
        }
        if (search.getCreateda()!=null){
            wrapper.gt("created",search.getCreateda());
        }
        if (search.getCreatedb()!=null){
            wrapper.lt("created",search.getCreatedb());
        }
        if (StringUtils.hasText(search.getKey())){
            wrapper.like("name",search.getKey());
        }
        Page<Copvo> page = copvoService.page(copPage, wrapper);
        return new Result(200,"",page);
    }

}
